home *** CD-ROM | disk | FTP | other *** search
/ Professional Soft Collection 1.02 / Professional Soft Collection 1.02.iso / winutils / wingauge.zip / WTIMER.C < prev   
C/C++ Source or Header  |  1993-01-19  |  1KB  |  42 lines

  1. #pragma hdrfile "WinGauge.SYM"
  2. #include <win31.h>
  3. #include "wingauge.h"
  4. #include "wingauge.rh"
  5. #pragma hdrstop
  6.  
  7.  
  8. #define INTERVAL    5493        // Interval between messages in idle
  9.                     //   system * 100
  10.  
  11. #define    TIMESIZE    20        // Size of array of time intervals
  12.  
  13. static    WORD    awTimes[TIMESIZE],    // Time interval array
  14.                     //   (initialized to 0 by default)
  15.         wSumTimes = 0;        // Sum of interval array
  16. static    short    sCount = -1,        // Count of collecting messages
  17.         sIndex = 0;        // Current time array index
  18. static    DWORD    lPrevTime;        // "Old current" time -- used for
  19.                     //   interval calculating
  20.  
  21.  
  22. WORD wmTimer(void)
  23. { DWORD lTime = GetCurrentTime();    // Current system time
  24.  
  25.   if( sCount < TIMESIZE )        // Have we collected TIMESIZE intvls?
  26.     ++sCount;
  27.   if( sCount == 0 )            // If it is first time...
  28.     { lPrevTime = lTime;        //    store it and bye
  29.       return 0;
  30.     }
  31.  
  32.   wSumTimes -= awTimes[sIndex];        // Subtract oldest interval,
  33.   wSumTimes += ( awTimes[sIndex] = (WORD)(lTime - lPrevTime) );
  34.                     //   calculate new one,
  35.                     //   store it in interval array
  36.                     //   and add it to total sum.
  37.   if( ++sIndex == TIMESIZE )        // Check array index for overflow
  38.     sIndex = 0;
  39.   lPrevTime = lTime;
  40.   return 100 - MyMulDiv( INTERVAL, sCount, wSumTimes );
  41. }
  42.